package com.kkb.shopcenter.controller;


import com.github.pagehelper.PageInfo;
import com.kkb.shopcenter.api.BrandService;
import com.kkb.shopcenter.common.common.HttpResult;
import com.kkb.shopcenter.common.pojo.BrandInfo;
import io.swagger.annotations.*;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(value = "品牌控制器", protocols = "http", description = "品牌控制器")
@RestController
@RequestMapping("/api")
public class BrandController {

    @Reference
    private BrandService brandService;

    @ApiOperation(value = "品牌分页查询",notes = "接受分页参数page,pageSize")
    @GetMapping("/getBrand")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "pageNum", value = "第几页", required = true, dataType = "int"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "一页显示多少条数据", required = true, dataType = "int")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "条件分页查询品牌成功"),
            @ApiResponse(code = 500, message = "条件分页查询品牌失败,后台服务出现异常"),
            @ApiResponse(code = 401, message = "代表此操作无权限访问"),
            @ApiResponse(code = 400, message = "表示请求参数错误"),
    })
    public HttpResult getBrand(@RequestParam(value="page",defaultValue="1")int pageNo, @RequestParam(value="pageSize",defaultValue="10")int pageSize){
        PageInfo<BrandInfo> brands = brandService.getBrand(pageNo+1,pageSize);
        return HttpResult.success(brands);
    }

    @ApiOperation(value = "品牌管理之新建",notes = "接受对象参数brand")
    @PostMapping("/addBrand")
    @ApiResponses({
            @ApiResponse(code = 200, message = "新增品牌成功"),
            @ApiResponse(code = 500, message = "新增品牌失败,后台服务出现异常"),
            @ApiResponse(code = 401, message = "代表此操作无权限访问"),
            @ApiResponse(code = 400, message = "表示请求参数错误"),
    })
    public HttpResult addBrand(@RequestBody BrandInfo brand){
        int result = brandService.insertBrand(brand);
        //接口已通
        return HttpResult.success(result);
    }

    @ApiOperation(value = "品牌管理之修改",notes = "接受对象参数brandId")
    @PutMapping("/updateBrand")
    @ApiResponses({
            @ApiResponse(code = 200, message = "修改回显品牌成功"),
            @ApiResponse(code = 500, message = "修改回显品牌失败,后台服务出现异常"),
            @ApiResponse(code = 401, message = "代表此操作无权限访问"),
            @ApiResponse(code = 400, message = "表示请求参数错误"),
    })
    public HttpResult updateBrand(@RequestBody BrandInfo brand){
        int result = brandService.updateBrand(brand);
        //接口已通
        return HttpResult.success(result);
    }

    @ApiOperation(value = "品牌管理之删除",notes = "接受对象参数ids")
    @DeleteMapping("/deleteBrand/{id}")
    @ApiResponses({
            @ApiResponse(code = 200, message = "批量删除品牌成功"),
            @ApiResponse(code = 500, message = "批量删除品牌失败,后台服务出现异常"),
            @ApiResponse(code = 401, message = "代表此操作无权限访问"),
            @ApiResponse(code = 400, message = "表示请求参数错误"),
    })
    public HttpResult deleteBrand(@PathVariable("id") Integer id){
        //
        int result = brandService.deleteBrand(id);
        return HttpResult.success(result);
    }

    @ApiOperation("不分页获取所有品牌列表")
    @GetMapping("/getAllBrand")
    public HttpResult getAllBrand(){
        List<BrandInfo> brandList = brandService.getAllBrand();
        return HttpResult.success(brandList);
    }
}
